package suncertify.db.test;

import java.rmi.RemoteException;

import suncertify.contractors.exceptions.ContractorsInitializationException;
import suncertify.db.Data;
import suncertify.db.DatabaseAccessException;
import suncertify.db.DatabaseFormatException;
import suncertify.db.DuplicateKeyException;

public class test1 {

    private static Data data;
    private static suncertify.remoting.RemoteContractorsAccessImpl remoteContractors;

    private static void test() {

    }

    public static void main(String[] args) throws DatabaseFormatException, DatabaseAccessException, RemoteException,
	    ContractorsInitializationException {

	data = new Data("C:\\Data\\SCJD\\Copy of Real Assignment\\work-db-2x2.db");
	// remoteContractors = new
	// RemoteContractorsAccessImpl("C:\\Data\\SCJD\\Copy of Real Assignment\\work-db-2x2.db");

	// runTest_RmiThreadCount();

	// runStopServer1();

	// runTestScenario1();
	// runTestScenario2();
	// runTestScenario3();
	// runTestScenario4();
	// runTestScenario5();
	// runTestScenario6();
	// runTestScenario7();
	// runTestScenario8();
	// runTestScenario9();
	// runTestScenario10();

	// runTestScenarioB1();
	// runTestScenarioB2();
	// runTestScenarioB4();
	// runTestScenarioB6();
	// runTestScenarioB7();

	// runTestScenarioC1();
	runTestScenarioC2();
    }

    /**
     * @param args
     *            Only for test purposes.
     */
    // public static void main(String args[]) {
    //
    // System.out.println(isNameValid(null));
    // System.out.println(isNameValid("@Dogs with Tools"));
    //
    // System.out.println(isNameValid(""));
    // System.out.println(isNameValid("   "));
    // System.out.println(isNameValid("dogs\n with\n tools"));
    // System.out.println(isNameValid("\ndogs\n with\n tools"));
    // System.out.println(isNameValid("5dogs \t with tools"));
    // System.out.println(isNameValid("Dogs & Tools"));
    // System.out.println(isNameValid("Dogs &, Tools"));
    //
    // System.out.println(isNameValid("dogs with tools"));
    // System.out.println(isNameValid("Dogs With tools"));
    // System.out.println(isNameValid("   DOGS WITH TOOLS  "));
    // System.out.println(isNameValid("D(**^&*(i_OGS WITH TOOLS"));
    // System.out.println(isNameValid("A"));
    // System.out.println(isNameValid("  123"));
    // System.out.println(isNameValid(" a"));
    // System.out.println(isNameValid("a"));
    // System.out.println(isNameValid("@"));
    // System.out.println(isNameValid("@!@#$%$%^&*"));
    // System.out.println(isNameValid("a@!@#$%$%^&*"));
    // System.out.println(isNameValid("0@!@#$%$%^&*"));
    // System.out
    // .println(isNameValid("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"));
    //
    // System.out.println(isLocationValid(null)); //
    // System.out.println(isLocationValid("")); //
    // System.out.println(isLocationValid("     ")); //
    // System.out.println(isLocationValid("123456790123456790123456790123456790123456790123456790abcd"));
    // //
    // System.out.println(isLocationValid("   12345679_12345679_12345679_12345679_12345679_12345679_1234   "));
    // //
    // System.out.println(isLocationValid("123456789_123456789_123456789_123456789_123456789_123456789_12345"));
    // //
    // System.out.println(isLocationValid("$")); //
    // System.out.println(isLocationValid("$adasdf")); //
    // System.out.println(isLocationValid("  $asdfdf")); //
    //
    // System.out.println(isSpecialtiesValid(null)); //
    // System.out.println(isSpecialtiesValid("")); //
    // System.out.println(isSpecialtiesValid("     ")); //
    // System.out.println(isSpecialtiesValid("12345679_12345679_12345679_12345679_12345679_12345679_1234"));
    // //
    // System.out.println(isSpecialtiesValid("123456789_123456789_123456789_123456789_123456789_123456789_12345"));
    // //
    // System.out.println(isSpecialtiesValid("$")); //
    // System.out.println(isSpecialtiesValid("$adasdf")); //
    // System.out.println(isSpecialtiesValid("  $asdfdf")); //
    //
    // System.out.println(isRateValid(null));
    // System.out.println(isRateValid(""));
    // System.out.println(isRateValid("   "));
    // System.out.println(isRateValid("$1.00"));
    // System.out.println(isRateValid("$1000.00"));
    // System.out.println(isRateValid("$1\n0.00"));
    // System.out.println(isRateValid("$10.00"));
    // System.out.println(isRateValid(" $1.00"));
    // System.out.println(isRateValid("$0.50"));
    // System.out.println(isRateValid("$.50"));
    // System.out.println(isRateValid("$1234567"));
    // System.out.println(isRateValid("$9999.88"));
    // System.out.println(isRateValid("a9999.88"));
    // System.out.println(isRateValid("9999.88"));
    // System.out.println(isRateValid("$39999.88"));
    // System.out.println(isRateValid("$9999886"));
    // System.out.println(isRateValid("$3999.885"));
    // System.out.println(isRateValid("$39a9.85"));
    //
    // System.out.println(isSizeValid(null));
    // System.out.println(isSizeValid(""));
    // System.out.println(isSizeValid("   "));
    // System.out.println(isSizeValid("1"));
    // System.out.println(isSizeValid("12"));
    // System.out.println(isSizeValid("123"));
    // System.out.println(isSizeValid("1234"));
    // System.out.println(isSizeValid("12345"));
    // System.out.println(isSizeValid("123456"));
    // System.out.println(isSizeValid("1.5"));
    // System.out.println(isSizeValid("01"));
    // System.out.println(isSizeValid("  123456  "));
    // System.out.println(isSizeValid("123456"));
    // System.out.println(isSizeValid("123456789"));
    // System.out.println(isSizeValid("-123"));
    // System.out.println(isSizeValid("a334"));
    // System.out.println(isSizeValid("44s33"));
    // System.out.println(isSizeValid("1\n23"));
    //
    // System.out.println(isOwnerValid(null));
    // System.out.println(isOwnerValid(""));
    // System.out.println(isOwnerValid("  "));
    // System.out.println(isOwnerValid("1234567"));
    // System.out.println(isOwnerValid("123456789"));
    // System.out.println(isOwnerValid("12345678"));
    // System.out.println(isOwnerValid("  12345678  "));
    // System.out.println(isOwnerValid("  123 5678  "));
    // System.out.println(isOwnerValid("$1234567"));
    // System.out.println(isOwnerValid("a1234567"));
    //
    // }

    /*
     * Each user updates only one record n times.
     * 
     * Each user access a different record.
     * 
     * Test Objectives
     * 
     * 1) Write access to different records are serialized! in other words each Data.updateRecord must start and end by
     * the same thread.
     * 
     * 2) When one thread owns the Data.updateRecord writeLock then all other threads are blocked.
     * 
     * 3) Data.lock calls will not cause any blocking because each thread locks a different record.
     */
    private static void runTestScenario1() {

	LockUpdateUnlockUser userA = new LockUpdateUnlockUser("A", data, 1, 1, 1000);
	LockUpdateUnlockUser userB = new LockUpdateUnlockUser("B", data, 2, 2, 1000);
	LockUpdateUnlockUser userC = new LockUpdateUnlockUser("C", data, 3, 3, 1000);
	LockUpdateUnlockUser userD = new LockUpdateUnlockUser("D", data, 4, 4, 1000);
	LockUpdateUnlockUser userE = new LockUpdateUnlockUser("E", data, 5, 5, 1000);

	userA.start();
	userB.start();
	userC.start();
	userD.start();
	userE.start();
    }

    /*
     * Each user does lock, update and unlock for n times, on the same record!
     * 
     * Test Objectives:
     * 
     * 1) Make sure n - 1 threads wait until the record is unlocked.
     * 
     * 2) No deadlock happens. All users finish their iterations.
     * 
     * 3) During long Write periods only LockManager.lock and unlock activities are possible.
     * 
     * 4) The number of 'going to sleep!' messages must equal the number of 'just woke up!' messages.
     */
    private static void runTestScenario2() {

	LockUpdateUnlockUser userA = new LockUpdateUnlockUser("A", data, 1, 1, 100);
	LockUpdateUnlockUser userB = new LockUpdateUnlockUser("B", data, 1, 1, 100);
	LockUpdateUnlockUser userC = new LockUpdateUnlockUser("C", data, 1, 1, 100);
	LockUpdateUnlockUser userD = new LockUpdateUnlockUser("D", data, 1, 1, 100);
	LockUpdateUnlockUser userE = new LockUpdateUnlockUser("E", data, 1, 1, 100);

	LockUpdateUnlockUser userF = new LockUpdateUnlockUser("F", data, 1, 1, 100);
	LockUpdateUnlockUser userG = new LockUpdateUnlockUser("G", data, 1, 1, 100);
	LockUpdateUnlockUser userH = new LockUpdateUnlockUser("H", data, 1, 1, 100);
	LockUpdateUnlockUser userI = new LockUpdateUnlockUser("I", data, 1, 1, 100);
	LockUpdateUnlockUser userJ = new LockUpdateUnlockUser("J", data, 1, 1, 100);

	userA.start();
	userB.start();
	userC.start();
	userD.start();
	userE.start();

	userF.start();
	userG.start();
	userH.start();
	userI.start();
	userJ.start();
    }

    /*
     * Add 1000 - 28 records to the database!
     * 
     * 10 threads each deletes 100 records. At the end all 1000 records must be deleted.
     * 
     * Objectives:
     * 
     * 1) All threads finish without deadlock.
     * 
     * 2) No sleep and wait will happen because each record is accessed once only.
     * 
     * 3)
     */
    private static void runTestScenario3() {

	String[] newRecord;

	for (int i = 0; i < 1000 - 28; ++i) {

	    newRecord = new String[6];

	    newRecord[0] = "name " + Integer.toString(i);
	    newRecord[1] = "location " + Integer.toString(i);
	    newRecord[2] = "specialties " + Integer.toString(i);
	    newRecord[3] = "10";
	    newRecord[4] = "$20.00";
	    newRecord[5] = "10300300";

	    try {
		data.createRecord(newRecord);
	    } catch (DuplicateKeyException e) {
		e.printStackTrace();
	    }
	}

	// now we have 1000 records :-) 0 -> 999

	LockDeleteUnlockUser user1 = new LockDeleteUnlockUser("A", data, 0, 99, 1);
	LockDeleteUnlockUser user2 = new LockDeleteUnlockUser("B", data, 100, 199, 1);
	LockDeleteUnlockUser user3 = new LockDeleteUnlockUser("C", data, 200, 299, 1);
	LockDeleteUnlockUser user4 = new LockDeleteUnlockUser("D", data, 300, 399, 1);
	LockDeleteUnlockUser user5 = new LockDeleteUnlockUser("E", data, 400, 499, 1);
	LockDeleteUnlockUser user6 = new LockDeleteUnlockUser("F", data, 500, 599, 1);
	LockDeleteUnlockUser user7 = new LockDeleteUnlockUser("G", data, 600, 699, 1);
	LockDeleteUnlockUser user8 = new LockDeleteUnlockUser("I", data, 700, 799, 1);
	LockDeleteUnlockUser user9 = new LockDeleteUnlockUser("J", data, 800, 899, 1);
	LockDeleteUnlockUser user10 = new LockDeleteUnlockUser("K", data, 900, 999, 1);

	user1.start();
	user2.start();
	user3.start();
	user4.start();
	user5.start();
	user6.start();
	user7.start();
	user8.start();
	user9.start();
	user10.start();

    }

    /*
     * Three searchByCriteria users. Each user has a unique search criteria. Each user repeats his search n times.
     * 
     * Objectives:
     * 
     * 1) No deadlocks, all threads finish correctly.
     * 
     * 2) Each user finds the same results.
     */
    private static void runTestScenario4() {

	// in default database name=dogs returns 6 results.
	FindByCriteriaUser userA = new FindByCriteriaUser("dogs1", data, 1000, new String[] { "dogs", "", "", "", "",
		"" });

	// in default database name=dogs returns 6 results.
	FindByCriteriaUser userB = new FindByCriteriaUser("dogs2", data, 100,
		new String[] { "dogs", "", "", "", "", "" });

	// in default database location=smallville returns 2 results.
	FindByCriteriaUser userC = new FindByCriteriaUser("smallville", data, 1000, new String[] { "", "small", "", "",
		"", "" });

	// in default database location=smallville returns 2 results.
	FindByCriteriaUser userD = new FindByCriteriaUser("smallville", data, 100, new String[] { "", "smallville", "",
		"", "", "" });

	// in an empty database this has 1 match
	FindByCriteriaUser userE = new FindByCriteriaUser("nameLocation1", data, 1000, new String[] { "h", "p", "", "",
		"", "" });

	// in an empty database this has 1 match
	FindByCriteriaUser userF = new FindByCriteriaUser("nameLocation2", data, 100, new String[] { "h", "p", "", "",
		"", "" });

	userA.start();
	// userB.start();

	userC.start();
	// userD.start();

	userE.start();
	// userF.start();
    }

    /*
     * Each user reads all records from 0 to 27 n times.
     * 
     * Objectives:
     * 
     * 1) No deadlocks. All threads finish successfully.
     * 
     * 2)
     */
    private static void runTestScenario5() {

	ReadRecordUser readUser1 = new ReadRecordUser("A", data, 0, 27, 100);
	ReadRecordUser readUser2 = new ReadRecordUser("B", data, 0, 27, 100);
	ReadRecordUser readUser3 = new ReadRecordUser("C", data, 0, 27, 100);
	ReadRecordUser readUser4 = new ReadRecordUser("D", data, 0, 27, 100);
	ReadRecordUser readUser5 = new ReadRecordUser("E", data, 0, 27, 100);

	readUser1.start();
	readUser2.start();
	readUser3.start();
	readUser4.start();
	readUser5.start();
    }

    /*
     * One user reads record x
     * 
     * One user findByCriteria record x
     * 
     * One user updates record x
     * 
     * One user deletes record x
     * 
     * One user creates record x
     * 
     * Objectives:
     * 
     * 1)No deadlocks.
     * 
     * 2) All users finish their iterations.
     * 
     * 3)
     */
    private static void runTestScenario6() {

	ReadRecordUser readUser = new ReadRecordUser("ReadUser", data, 10, 10, 100);

	FindByCriteriaUser searchUser = new FindByCriteriaUser("SearchUser", data, 100, new String[] { "swan", "digit",
		"ROOFING", "", "", "" });

	ReadAllRecordsUser readAllUser = new ReadAllRecordsUser("GetAllRecordsUser", data, 100);

	LockUpdateUnlockUser updateUser = new LockUpdateUnlockUser("UpdateUser", data, 10, 10, 100);

	LockDeleteUnlockUser deleteUser = new LockDeleteUnlockUser("DeleteUser", data, 11, 100, 1);

	AddUser addUser = new AddUser("AddUser", data, 100);

	readUser.start();
	searchUser.start();
	updateUser.start();
	readAllUser.start();
	// deleteUser.start();
	addUser.start();
    }

    /*
     * Objectives:
     * 
     * 1) No deadlocks.
     * 
     * 2) Completion of all iterations.
     */
    private static void runTestScenario7() {

	LockUpdateUnlockUser updateUser = new LockUpdateUnlockUser("UpdateUser", data, 10, 10, 1000);
	ReadRecordUser readUser = new ReadRecordUser("ReadUser", data, 10, 10, 1000);

	updateUser.start();
	readUser.start();
    }

    /*
     * Objectives:
     * 
     * 1) no deadlocks.
     * 
     * 2) completion of all iterations.
     */
    private static void runTestScenario8() {

	AddUser addUser1 = new AddUser("AddUser 1", data, 100);
	AddUser addUser2 = new AddUser("AddUser 2", data, 100);
	AddUser addUser3 = new AddUser("AddUser 3", data, 100);
	AddUser addUser4 = new AddUser("AddUser 4", data, 100);
	AddUser addUser5 = new AddUser("AddUser 5", data, 100);

	addUser1.start();
	addUser2.start();
	addUser3.start();
	addUser4.start();
	addUser5.start();
    }

    /**
     * Close
     */
    private static void runTestScenario9() {

	CloseUser closeUser1 = new CloseUser("CloseUser1", data, 100);
	CloseUser closeUser2 = new CloseUser("CloseUser2", data, 100);
	CloseUser closeUser3 = new CloseUser("CloseUser3", data, 100);
	CloseUser closeUser4 = new CloseUser("CloseUser4", data, 100);
	CloseUser closeUser5 = new CloseUser("CloseUser5", data, 100);

	closeUser1.start();
	closeUser2.start();
	closeUser3.start();
	closeUser4.start();
	closeUser5.start();
    }

    /**
     * getAllRecords
     */
    private static void runTestScenario10() {

	ReadAllRecordsUser readAllRecordsUser1 = new ReadAllRecordsUser("ReadAllRecordsUser1", data, 100);

	ReadAllRecordsUser readAllRecordsUser2 = new ReadAllRecordsUser("ReadAllRecordsUser2", data, 100);

	ReadAllRecordsUser readAllRecordsUser3 = new ReadAllRecordsUser("ReadAllRecordsUser3", data, 100);

	ReadAllRecordsUser readAllRecordsUser4 = new ReadAllRecordsUser("ReadAllRecordsUser4", data, 100);

	ReadAllRecordsUser readAllRecordsUser5 = new ReadAllRecordsUser("ReadAllRecordsUser5", data, 100);

	readAllRecordsUser1.start();
	readAllRecordsUser2.start();
	readAllRecordsUser3.start();
	readAllRecordsUser4.start();
	readAllRecordsUser5.start();
    }

    private static void runTestScenarioB1() {

	LockUpdateUnlockUser2 userA = new LockUpdateUnlockUser2("A", remoteContractors, 1, 1, 1000);
	LockUpdateUnlockUser2 userB = new LockUpdateUnlockUser2("B", remoteContractors, 2, 2, 1000);
	LockUpdateUnlockUser2 userC = new LockUpdateUnlockUser2("C", remoteContractors, 3, 3, 1000);
	LockUpdateUnlockUser2 userD = new LockUpdateUnlockUser2("D", remoteContractors, 4, 4, 1000);
	LockUpdateUnlockUser2 userE = new LockUpdateUnlockUser2("E", remoteContractors, 5, 5, 1000);

	userA.start();
	userB.start();
	userC.start();
	userD.start();
	userE.start();
    }

    private static void runTestScenarioB2() {

	LockUpdateUnlockUser2 userA = new LockUpdateUnlockUser2("A", remoteContractors, 1, 1, 100);
	LockUpdateUnlockUser2 userB = new LockUpdateUnlockUser2("B", remoteContractors, 1, 1, 100);
	LockUpdateUnlockUser2 userC = new LockUpdateUnlockUser2("C", remoteContractors, 1, 1, 100);
	LockUpdateUnlockUser2 userD = new LockUpdateUnlockUser2("D", remoteContractors, 1, 1, 100);
	LockUpdateUnlockUser2 userE = new LockUpdateUnlockUser2("E", remoteContractors, 1, 1, 100);

	LockUpdateUnlockUser2 userF = new LockUpdateUnlockUser2("F", remoteContractors, 1, 1, 100);
	LockUpdateUnlockUser2 userG = new LockUpdateUnlockUser2("G", remoteContractors, 1, 1, 100);
	LockUpdateUnlockUser2 userH = new LockUpdateUnlockUser2("H", remoteContractors, 1, 1, 100);
	LockUpdateUnlockUser2 userI = new LockUpdateUnlockUser2("I", remoteContractors, 1, 1, 100);
	LockUpdateUnlockUser2 userJ = new LockUpdateUnlockUser2("J", remoteContractors, 1, 1, 100);

	userA.start();
	userB.start();
	userC.start();
	userD.start();
	userE.start();

	userF.start();
	userG.start();
	userH.start();
	userI.start();
	userJ.start();
    }

    private static void runTestScenarioB4() {

	// in default database name=dogs returns 6 results.
	FindByCriteriaUser2 userA = new FindByCriteriaUser2("dogs1", remoteContractors, 1000, new String[] { "dogs",
		"", "", "", "", "" });

	// in default database name=dogs returns 6 results.
	FindByCriteriaUser2 userB = new FindByCriteriaUser2("dogs2", remoteContractors, 100, new String[] { "dogs", "",
		"", "", "", "" });

	// in default database location=smallville returns 2 results.
	FindByCriteriaUser2 userC = new FindByCriteriaUser2("smallville", remoteContractors, 1000, new String[] { "",
		"small", "", "", "", "" });

	// in default database location=smallville returns 2 results.
	FindByCriteriaUser2 userD = new FindByCriteriaUser2("smallville", remoteContractors, 100, new String[] { "",
		"smallville", "", "", "", "" });

	// in an empty database this has 1 match
	FindByCriteriaUser2 userE = new FindByCriteriaUser2("nameLocation1", remoteContractors, 1000, new String[] {
		"h", "p", "", "", "", "" });

	// in an empty database this has 1 match
	FindByCriteriaUser2 userF = new FindByCriteriaUser2("nameLocation2", remoteContractors, 100, new String[] {
		"h", "p", "", "", "", "" });

	userA.start();
	// userB.start();

	userC.start();
	// userD.start();

	userE.start();
	// userF.start();
    }

    private static void runTestScenarioB6() {

	// ReadRecordUser2 readUser = new ReadRecordUser2("ReadUser", remoteContractors, 10, 10, 1000);
	//
	// FindByCriteriaUser2 searchUser = new FindByCriteriaUser2("SearchUser", remoteContractors, 1000, new String[]
	// {
	// "swan", "digit", "ROOFING", "", "", "" });
	//
	// ReadAllRecordsUser2 readAllUser = new ReadAllRecordsUser2("GetAllRecordsUser", remoteContractors, 1000);
	//
	// LockUpdateUnlockUser2 updateUser = new LockUpdateUnlockUser2("UpdateUser", remoteContractors, 10, 10, 1000);
	//
	// readUser.start();
	// searchUser.start();
	// updateUser.start();
	// readAllUser.start();
    }

    /*
     * 1) Make sure stop, terminate and X cause all running threads to finish.
     * 
     * 2) Blocked calls on the Data readWrite should all throw illegalSTate and the clients should terminate.
     * 
     * 3) Blocked calls in the LockManager should all wake up and throw IllegalStateException.
     * 
     * 4) Mix of blocking calls in the Data and lock manager must end.
     * 
     * 5) Try the threads on the same record with sleeps so that we have blocking threads in the lockManager.
     * 
     * 6) Try the threads on different records so that we have sleeping customers on the data lock.
     */
    private static void runStopServer1() {

	LockUpdateUnlockUser3 userA = new LockUpdateUnlockUser3("updateUserA", "FarisVaio", 12345, 1, 1, 100);
	LockUpdateUnlockUser3 userB = new LockUpdateUnlockUser3("updateUserB", "FarisVaio", 12345, 1, 1, 100);
	LockUpdateUnlockUser3 userC = new LockUpdateUnlockUser3("updateUserC", "FarisVaio", 12345, 1, 1, 100);
	LockUpdateUnlockUser3 userD = new LockUpdateUnlockUser3("updateUserD", "FarisVaio", 12345, 1, 1, 100);
	LockUpdateUnlockUser3 userE = new LockUpdateUnlockUser3("updateUserE", "FarisVaio", 12345, 1, 1, 100);

	userA.start();
	userB.start();
	userC.start();
	userD.start();
	userE.start();
    }

    private static void runTest_RmiThreadCount() {

	int count = 100;
	FindByCriteria3[] findUsers = new FindByCriteria3[count];

	for (int i = 0; i < count; ++i) {
	    findUsers[i] = new FindByCriteria3("user" + Integer.toString(i), "localhost", 12345, 1000);
	    findUsers[i].start();
	}
    }

    /**
     * 1) Make sure n - 1 threads wait until the record is unlocked.
     * 
     * 2) No deadlock happens. All users finish their iterations.
     * 
     * 3) During long Write periods only LockManager.lock and unlock activities are possible.
     * 
     * 4) The number of 'going to sleep!' messages must equal the number of 'just woke up!' messages.
     */
    private static void runTestScenarioC1() {

	LockUpdateUnlockUser3 userA = new LockUpdateUnlockUser3("updateUser1", "localhost", 12345, 10, 10, 500);
	LockUpdateUnlockUser3 userB = new LockUpdateUnlockUser3("updateUser2", "localhost", 12345, 10, 10, 500);
	LockUpdateUnlockUser3 userC = new LockUpdateUnlockUser3("updateUser3", "localhost", 12345, 10, 10, 500);
	LockUpdateUnlockUser3 userD = new LockUpdateUnlockUser3("updateUser4", "localhost", 12345, 10, 10, 500);
	LockUpdateUnlockUser3 userE = new LockUpdateUnlockUser3("updateUser5", "localhost", 12345, 10, 10, 500);

	userA.start();
	userB.start();
	userC.start();
	userD.start();
	userE.start();
    }

    /*
     * 1) Write access to different records are serialized! in other words each Data.updateRecord must start and end by
     * the same thread.
     * 
     * 2) When one thread owns the Data.updateRecord writeLock then all other threads are blocked.
     * 
     * 3) Data.lock calls will not cause any blocking because each thread locks a different record.
     */
    private static void runTestScenarioC2() {

	LockUpdateUnlockUser3 userA = new LockUpdateUnlockUser3("updateUser1", "localhost", 12345, 1, 1, 500);
	LockUpdateUnlockUser3 userB = new LockUpdateUnlockUser3("updateUser2", "localhost", 12345, 2, 2, 500);
	LockUpdateUnlockUser3 userC = new LockUpdateUnlockUser3("updateUser3", "localhost", 12345, 3, 3, 500);
	LockUpdateUnlockUser3 userD = new LockUpdateUnlockUser3("updateUser4", "localhost", 12345, 4, 4, 500);
	LockUpdateUnlockUser3 userE = new LockUpdateUnlockUser3("updateUser5", "localhost", 12345, 5, 5, 500);

	userA.start();
	userB.start();
	userC.start();
	userD.start();
	userE.start();
    }
}
